<!-- 消息通知 -->
<template>
    <view class="container">
        <search-bar :placeholderText="placeholderText" :actions="actions" @searchFn="searchFn"> </search-bar>
        <view class="main">
            <mescroll-uni
                v-if="loadOk"
                ref="mescrollRef"
                @init="mescrollInit"
                :height="listHeight"
                :down="downOption"
                @down="downRefresh"
                :up="upOption"
                @up="getData">
                <message-item v-for="(item, index) in datas" :key="index" :data="item"></message-item>
            </mescroll-uni>
        </view>
    </view>
</template>
<script>
import storage from "@/uni-sub-base/utils/storage.js"
import messageItem from "@/pages_supplier/components/message/message-item.vue"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
import { GetMessageAlertList, AllReduceAlert } from "@/pages_supplier/service/api/supplier.js"
import searchBar from "@/pages_supplier/components/common/search-bar.vue"
export default {
    components: {
        messageItem,
        searchBar,
    },
    data() {
        return {
            listHeight: "500rpx",
            loadOk: false,
            datas: [],
            actions: [],
            placeholderText: "快速查找标题和内容",
            requestData: {
                keyWord: "",
            },
        }
    },
    mounted() {
        this.getListHeight()
    },
    onShow() {
        if (this.loadOk) {
            setTimeout((e) => {
                //#ifndef MP
                this.refresh()
                //#endif
            }, 300)
        }
    },
    methods: {
        getListHeight() {
            //获取商品高度
            getElementHeight(this, ".main", (e) => {
                this.listHeight = e + "px"
                this.loadOk = true
                setTimeout((e) => {
                    //#ifndef MP
                    this.refresh()
                    //#endif
                }, 300)
            })
        },
        //获取列表数据
        getData(page) {
            let param = {}
            param.pageSize = page.size
            param.pageIndex = page.num
            let path = "?pageSize=" + param.pageSize + "&pageIndex=" + param.pageIndex
            if (this.requestData.keyWord) {
                param.keyWord = this.requestData.keyWord
                path =
                    "?pageSize=" +
                    param.pageSize +
                    "&pageIndex=" +
                    param.pageIndex +
                    "&keyWord=" +
                    this.requestData.keyWord
            }
            GetMessageAlertList(param, path).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                } else {
                    this.mescroll.endBySize(0, 0)
                }
            })
        },
        //搜索
        searchFn(searchKey) {
            this.requestData.keyWord = searchKey
            this.refresh(this.requestData)
        },
        //刷新
        refresh() {
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        onNavigationBarButtonTap(e) {
            AllReduceAlert().then((res) => {
                if (res.State == 1) {
                    this.easyToast("操作成功！")
                    setTimeout((e) => {
                        this.refresh()
                    }, 1800)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss"></style>
